package com.jeesite.modules.banuser.users.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

import java.io.Serial;
import java.util.Date;

/**
 * usersEntity
 * @author k
 * @version 2025-08-21
 */
@Table(name="users", alias="a", label="users信息", columns={
		@Column(name="id", attrName="tid", label="id", isPK=true),
		@Column(name="username", attrName="username", label="username", queryType=QueryType.LIKE),
		@Column(name="password", attrName="password", label="password"),
		@Column(name="nickname", attrName="nickname", label="nickname"),
		@Column(name="avatar", attrName="avatar", label="avatar"),
		@Column(name="role", attrName="role", label="role"),
		@Column(name="status", attrName="status", label="status"),
		@Column(name="created_at", attrName="createdAt", label="created_at", isUpdateForce=true),
		@Column(name="updated_at", attrName="updatedAt", label="updated_at", isUpdateForce=true),
	}, orderBy="a.id DESC"
)
public class Users extends DataEntity<Users> {
	
	@Serial
	private static final long serialVersionUID = 1L;
	private Long tid;		// id
	private String username;		// username
	private String password;		// password
	private String nickname;		// nickname
	private String avatar;		// avatar
	private String role;		// role
	private Date createdAt;		// created_at
	private Date updatedAt;		// updated_at

	public Users() {
		this(null);
	}
	
	public Users(String id){
		super(id);
	}
	
	@JsonSerialize(using = ToStringSerializer.class)
	public Long getTid() {
		return tid;
	}

	public void setTid(Long tid) {
		this.tid = tid;
	}
	
	@NotBlank(message="username不能为空")
	@Size(min=0, max=50, message="username长度不能超过 50 个字符")
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	@NotBlank(message="password不能为空")
	@Size(min=0, max=255, message="password长度不能超过 255 个字符")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	@Size(min=0, max=100, message="nickname长度不能超过 100 个字符")
	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	
	@Size(min=0, max=255, message="avatar长度不能超过 255 个字符")
	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}
	
	@Size(min=0, max=20, message="role长度不能超过 20 个字符")
	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
	public Date getUpdatedAt() {
		return updatedAt;
	}

	public void setUpdatedAt(Date updatedAt) {
		this.updatedAt = updatedAt;
	}

	@Override
	public String toString() {
		return "Users{" +
				"tid=" + tid +
				", username='" + username + '\'' +
				", password='" + password + '\'' +
				", nickname='" + nickname + '\'' +
				", avatar='" + avatar + '\'' +
				", role='" + role + '\'' +
				", createdAt=" + createdAt +
				", updatedAt=" + updatedAt +
				", status='" + status + '\'' +
				'}';
	}
}